﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using Tebbee.UI.Client.AdvertiseSer;

namespace Tebbee.UI.Client.Controllers.GuestApi
{
    public class HomePageController : ApiController
    {
        private readonly AdvertiseSerClient db = new AdvertiseSerClient();

        public IEnumerable<Advertise_TOP_Result> GetTop()
        {
            var tmp = db.GetAdvertiseTop("Home");
            return tmp;
        }

        public HttpResponseMessage GetLink(int id)
        {
            string type = "";
            IEnumerable<Advertise_GetLink_Result> list = db.GetAdvertiseLink(out type, id);
            return Request.CreateResponse(HttpStatusCode.OK, new { list, type });
        }

        public class RequestString
        {
            public string searchString { get; set; }
        }

        public HttpResponseMessage SearchAdvertise(RequestString request)
        {
            if (ModelState.IsValid)
            {
                IEnumerable<Advertise_Search_Result>  list = db.Advertise_Search(request.searchString);
                return Request.CreateResponse(HttpStatusCode.Created, list);

            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
    }
}
